package com.shop.pandian.app.service.impl;

import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.shop.pandian.app.dao.AcctUserDAO;
import com.shop.pandian.app.model.AcctAuthority;
import com.shop.pandian.app.model.AcctRole;
import com.shop.pandian.app.model.AcctUser;
import com.shop.pandian.app.service.AcctUserService;
import com.shop.pandian.framework.base.dao.EntityDAO;
import com.shop.pandian.framework.base.service.BaseServiceImpl;

@Service
@Transactional
public class AcctUserServiceImpl extends BaseServiceImpl<AcctUser, Long> implements AcctUserService {

	@Autowired
	private AcctUserDAO acctUserDAO;
	
	@Override
	public AcctUser getUserByLoginName(String loginName) {
		List<AcctUser> list = acctUserDAO.findAllBy(new String[]{"loginName"}, new String[]{loginName});
		if(list != null && !list.isEmpty()){
			return list.get(0);
		}
		return null;
	}

	@Override
	public EntityDAO getEntityDAO() {
		return acctUserDAO;
	}
	
	@Override
	public AcctUser getUserAndRolesbyId(Long id) {
		AcctUser user = getById(id);
		List<AcctRole> roleList = user.getRoleList();
		for (AcctRole role : roleList) {
			Set<AcctAuthority> authoritySet = role.getAuthorityList();
			for (AcctAuthority authority : authoritySet) {

			}
		}
		return user;
	}

}
